package com.cssw.fyzb.busi.api.live;

import com.cssw.fyzb.core.model.vo.live.AnchorManageVo;
import com.cssw.fyzb.busi.service.live.AnchorService;
import com.cssw.fyzb.busi.service.user.UserService;
import com.cssw.fyzb.core.model.dodb.CmfAnchorManage;
import com.cssw.fyzb.core.model.mos.UserMo;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import com.ydn.dbframe.plugin.activerecord.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 获取管理员列表
 *
 * @author wondream
 */
@Function(description = "获取管理员列表", parameters = {
        @Parameter(name = "anchorId", type = Type.String, description = "主播标识", required = true),
        @Parameter(name = "pageNumber", type = Type.String, description = "当前页，从1开始", required = true),
        @Parameter(name = "pageSize", type = Type.String, description = "页大小", required = true)
})
@Component
public class ListAnchorManage implements Action {

    @Autowired
    AnchorService anchorService;

    @Autowired
    UserService userService;

    @Override
    public Response execute(Request request) throws Exception {
        Long anchorId = request.getLong("anchorId");
        Integer pageNumber = request.getInteger("pageNumber");
        Integer pageSize = request.getInteger("pageSize");
        Page<CmfAnchorManage> page = anchorService.listAnchorManage(anchorId, pageNumber, pageSize);

        List<AnchorManageVo> list = new ArrayList<>();
        AnchorManageVo vo = null;
        for (CmfAnchorManage c : page.getList()) {
            vo = new AnchorManageVo();
            vo.setAnchorId(c.getAnchorId());
            vo.setManageId(c.getManageId());
            vo.setUserId(c.getUserId());
            UserMo userMo = userService.findById(c.getUserId());
            if (null != userMo){
                vo.setAvatar(userMo.getAvatar());
                vo.setNickName(userMo.getNickName());
            }
            list.add(vo);
        }
        return Response.success().put("list", list).put("total", page.getTotalPage()).put("count", page.getTotalRow());
    }
}

